/*
 * Copyright 2009-2010 the original author or authors.
 *
 * Licensed under the Apache license, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.internna.iwebjtracker.server.mail;

import javax.mail.Address;
import java.util.Collection;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.internna.iwebjtracker.project.model.IWebJTrackerUser;
import org.internna.iwebjtracker.server.Server;
import org.internna.iwebjtracker.server.connection.ServerConnection;
import org.internna.iwebjtracker.server.connection.ConnectionDetails;

/**
 *
 * @author Jose Noheda
 * @since 1.0
 */
public interface MailServer<S extends ServerConnection, C extends ConnectionDetails> extends Server<S, C> {

    /**
     * Creates an empty message
     *
     * @return a non null instance
     */
    MimeMessage createMessage();

    /**
     * Creates an empty message with a destination.
     *
     * @param to any (if null no destination will be set)
     * @return a non null instance
     */
    MimeMessage createMessage(String to);

    /**
     * Creates an empty message with a destination.
     *
     * @param name the name of the recipient
     * @param to the address of the recipient (if null no destination will be set)
     * @return a non null instance
     */
    MimeMessage createMessage(String name, String to);

    /**
     * Creates an empty message with a destination.
     *
     * @param address any (if null no destination will be set)
     * @return a non null instance
     */
    MimeMessage createMessage(Address address);

    /**
     * Creates an empty message with multiple destinations.
     *
     * @param users any
     * @return a non null instance
     */
    MimeMessage createMessage(Collection<IWebJTrackerUser> users);
    /**
     * Send one pending message stored in the mail server.
     */
    void send() throws MessagingException;

    /**
     * Asynchronously sends the message to the recipients.
     *
     * @param message any
     * @return true if the operation was successful (not ensuring the message will reach a destination)
     */
    boolean send(MimeMessage message);

}
